﻿<!DOCTYPE html>
<!--[if lt IE 7]>    <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="zh-cn" > <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="zh-cn" > <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="zh-cn" ><![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="zh-cn">
<!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>购物车</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no" />
    <meta name="”apple-mobile-web-app-capable”" content="”yes”" />

    <!-- 加载js/css -->
    <link type="text/css" rel="stylesheet" href="/shop/templates/yeshou/css/font-awesome.min.css?v=3">
    <link type="text/css" rel="stylesheet" href="/shop/templates/yeshou/css/wapmain.css?v=3344">
    <script type="text/javascript" src="/shop/templates/yeshou/js/zepto.min.js?v=333"></script>
    <script src="../../../scripts/jquery/jquery-2.1.0.min.js"></script>
    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "//hm.baidu.com/hm.js?7c10355ee0f6b21af208947325fd4ad7";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</head>
<body>
    <div id="J_Wrappear">
        <div class="lay-wrap J_MenuBody" id="J_MenuSwipe">
            <!--顶部-->
            <vt:template id="header" file="_header.html" charset="utf-8" />
            <!--end顶部-->
            <script>
                $(document).ready(function () {
                    initCart();
                });

                /**重新加载购物车数量和总价**/
                function initCart() {
                    $.ajax({
                        url: '/shop/shopmgr.ashx?wid={$wid}&openid={$openid}&myact=pcount&ss=' + Math.random(),
                        dataType: 'json',
                        async: false,
                        success: function (data) {

                            if (data.data > 0) {
                                var num = data.data;
                                var cart_a_link = $(".m-shop-cart");
                                if (num != 'undefined' && parseInt(num) > 0) {
                                    if (cart_a_link.find("i.shop-num").length > 0) {
                                        cart_a_link.find("i.shop-num").text(num);
                                    } else {
                                        cart_a_link.prepend($("<i class=\"shop-num\">" + num + "</i>"));
                                    }
                                }
                            } else {
                                $('#J_totalPrice').empty();
                                $('#J_toPay').attr('disabled', "true");
                                $('#J_toPay').addClass('u-disabled');
                                $('#J_cart_list').empty();
                                $('#J_cart_list').append($('<p id="J_cart_empty" class="empty">您的购物车是空的</p>'));
                                $(".btn-all").hide();
                            }
                        }
                    });
                    calc();
                }
            </script>

            <div class="lay-til J_MenuBody" id="J_SubHead">
                <div class="header-con">
                    <i class="arrow-back" onclick="history.go(-1)">
                        <img src="/shop/templates/yeshou/images/pay_03.png" alt="" /></i>
                    <h1>购物车</h1>
                </div>
            </div>
            <div class="lay-body lay-body2" id="J_MainBody">
                <div class="cart">
                    <div class="clearfix" id="J_cart_list">

                        <vt:foreach from="$cartlist" item="cproduct" index="i">
                        <ul class="pro-group J_DelNode"> 
                            <li class="pro-check">
                                <input type="checkbox" onclick="calc();" name="pro-check" class="J_ProCheck" checked="true" value="{$cproduct.id}" discount_price="" user_price="{$cproduct.avgPrice}" vip_price="" /></li>
                            <li class="pro-pic"><a href="{$cproduct.productUrl}">
                                <img src="{$cproduct.productPic}" alt="{$cproduct.shortDesc}" /></a></li> 
                            <li class="pro-info">
                                <div class="clearfix"> 
                                    <h2 class="pro-til"><a href="{$cproduct.productPic}">{$cproduct.shortDesc}</a></h2> 
                                    <p class="pro-name">{$cproduct.productName}</p> 
                                    <p class="pro-price">
                                        ￥{$cproduct.avgPrice}
                                    </p> 
                                </div>
                                <div class="clearfix">
                                    <p class="pro-standard fl"></p>
                                </div>
                            </li>
                            <li class="pro-del">
                                <div class="num fr">
                                    <button type="button" class="num-handle minus J_Minus"><i class="icon-minus"></i></button>
                                    <input type="text" class="J_In" value="{$cproduct.productNum}" min="1" cart-id="{$cproduct.id}" id="cart_id_{$cproduct.id}" disabled />
                                    <button type="button" class="num-handle add J_Add"><i class="icon-plus"></i></button>
                                </div>
                                <button type="button" class="fr J_Del" cart-id="{$cproduct.id}"><i class="icon-trash"></i></button>
                            </li>
                        </ul> 
                        </vt:foreach>

                    </div>

                    <!-- 全选、反选 -->
                    <div class="btn-all">
                        <input type="checkbox" class="J_Check" onclick="$(this).prop('checked') ? $('.J_ProCheck').prop('checked', true) : $('.J_ProCheck').prop('checked', false); calc();" />
                        全选
                    </div>
                </div>
            </div>

            <footer class="lay-foot J_MenuBody">

                <p class="fl" id="J_totalPrice">
                    总计：￥
				0
                </p>

                <button type="button" class="foot-btn" id="J_toPay">去结算</button>
            </footer>
        </div>
        <div class="m-mask J_MenuBody" id="J_Mask"></div>
        <!--左边菜单-->
        <vt:template id="_bottom" file="_bottom.html" charset="utf-8" />
        <!--end左边菜单-->
        <script type="text/javascript" src="/shop/templates/yeshou/js/main.js?v=1"></script>
        <script type="text/javascript" src="/shop/templates/yeshou/js/idangerous.swiper.min.js"></script>
        <script>
            function serchItems() {
                var skeywordVal = document.getElementById('skeyword').value;
                if (skeywordVal != '') {
                    window.location.href = "/shop/templates/yeshou/item/search.htm?searchKeyword=" + skeywordVal;
                } else {
                    alert('请输入搜索词');
                }
            }

            $("#skeyword").keydown(function (event) {
                if (event.keyCode == 13) {
                    serchItems();
                }
            });
        </script>



        <!-- Piwik -->
        <script type="text/javascript">
            var _paq = _paq || [];
            _paq.push(['trackPageView']);
            _paq.push(['enableLinkTracking']);
            (function () {
                var u = "//www.thebeastshop.com/piwik/";
                _paq.push(['setTrackerUrl', u + 'piwik.php']);
                _paq.push(['setSiteId', 1]);
                var userID = '', userName = '';
                userID != '' && _paq.push(['setCustomVariable', 1, 'userID', userID, 'visit']);
                userName != '' && _paq.push(['setCustomVariable', 2, 'userName', userName, 'visit']);
                _paq.push(['trackPageView']);
                var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
                g.type = 'text/javascript'; g.async = true; g.defer = true; g.src = u + 'piwik.js'; s.parentNode.insertBefore(g, s);
            })();
        </script>
        <noscript>
            <p>
                <img src="//www.thebeastshop.com/piwik/piwik.php?idsite=1" style="border: 0;" alt="" />
            </p>
        </noscript>
        <!-- End Piwik Code -->
    </div>
    <script type="text/javascript">
        /**数量增减**/
        $('.J_Minus').each(function () {
            $(this).on('click', function () {
                var $this = $(this);
                var $sub = $this.siblings('.J_In').eq(0);
                var valu = $sub.val();
                if (valu <= 1) {
                    alert("购物车数量为1，不能再减少");
                    return;
                }
                var a = --valu;
                $.ajax({
                    url: '/shop/shopmgr.ashx?myact=modifyNum',
                    data: {
                        ic: $sub.attr("cart-id"), bc: a
                    },
                    cache: false,
                    async: true,
                    success: function (data) {

                        $sub.attr("value", a);
                        window.location.href = "{$carturl}";
                    },
                    error: function (data) {
                        alert("操作失败，请刷新页面后重新尝试");
                    },
                    dataType: 'json'
                });

            });
        });

        $('.J_Add').each(function () {
            $(this).on('click', function () {
                var $this = $(this);
                var $sub = $this.siblings('.J_In').eq(0);
                var valu = $sub.val();
                var a = ++valu;
                $.ajax({
                    url: '/shop/shopmgr.ashx?myact=modifyNum',
                    data: { ic: $sub.attr("cart-id"), bc: a },
                    cache: false,
                    async: true,
                    success: function (data) { 
                        $sub.attr("value", a);
                        window.location.href = "{$carturl}";
                    },
                    error: function (data) {
                        alert("操作失败，请刷新页面后重新尝试");
                    },
                    dataType: 'json'
                });

            });
        });


        $('.J_Del').each(
				function () {
				    $(this).on('click', function () {
				        var $this = $(this);

				        $.ajax({
				            url: '/shop/shopmgr.ashx?myact=remove',
				            data: {
				                "id": $this.attr("cart-id")
				            },
				            success: function () {
				                initCart();

				                $this.parents('.J_DelNode').eq(0).fadeOut(1500, function () {
				                    $(this).remove();
				                    calc();
				                })
				            }
				        });
				    });

				});

        /**
        *计算勾选的价格
        */

        function calc() {
            var totalPrice = parseFloat(0);
            $('.J_ProCheck').each(function () {
                $this = $(this);
                if ($this.prop("checked")) {
                    var cartId = $this.attr("value");
                    var quantity = parseInt($("#cart_id_" + cartId).attr("value"));
                    var discount_price = $this.attr("discount_price");
                    var vip_price = $this.attr("vip_price");
                    var user_price = $this.attr("user_price");
                    if (discount_price != "" && discount_price != 'undefined' && discount_price > 0) {

                        totalPrice += parseFloat(discount_price) * quantity;
                    } else if (vip_price != "" && vip_price != 'undefined' && vip_price > 0) {

                        totalPrice += parseFloat(vip_price) * quantity;
                    } else {

                        totalPrice += parseFloat(user_price) * quantity;
                    }
                }
            });

            $("#J_totalPrice").html("");
            $("#J_totalPrice").html("总计：￥ " + totalPrice.toFixed(2));
        }

        $('#J_toPay').on('click', function () {
            var checkedCartIds = "";
            $('.J_ProCheck').each(function () {
                $this = $(this);
                if ($this.prop("checked")) {
                    checkedCartIds += $this.attr("value") + ",";
                }
            });
            if (checkedCartIds == 'undefined' || checkedCartIds.length <= 0) {
                alert("请选择您要购买的商品!");
                return;
            }

            location.href = '/shop/confirmOrder.aspx?wid={$wid}&openid={$openid}';
        });


    </script>
</body>
</html>
